﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using ExtAspNet;
using System.Data;
using Ylh.BLL;

public partial class Module_DepartmentManger_DepartmentIndex :PageBase 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.OnClientClick = Window1.GetShowReference("AddDepartment.aspx", "添加部门");

        if (!IsPostBack)
        {
            BindGvList();
        }

    }

    private void BindGvList()
    {
        DepartmentBLL debll = new DepartmentBLL(DbConnectionStr);

       Grid1.DataSource= debll.GetDepartMentInfo(-1);
       Grid1.DataBind();

    }
    protected void Grid1_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
    {
        string DepartmentID = Grid1.DataKeys[e.RowIndex][0].ToString();

        switch (e.CommandName)
        {
            case "UpdateDeInfo":
                PageContext.RegisterStartupScript(Window1.GetShowReference("AddDepartment.aspx?DepartmentID=" + DepartmentID, "修改部门信息"));
                break;
            case "UpdateHead":
                PageContext.RegisterStartupScript(Window2.GetShowReference("../StaffManger/StaffTree.aspx?DepartmentID=" + DepartmentID, "选择部门负责人"));
                break;
            default:
                break;
        }
    }

    protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
    {
        Grid1.PageIndex = e.NewPageIndex;
    }

    protected void BtnDel_Click(object sender, EventArgs e)
    {
        List<string >li=GetCheckID(Grid1);

        DepartmentBLL debll = new DepartmentBLL(DbConnectionStr);

        debll.DeleteDepartmentInfo(li);

        BindGvList();
        Alert.Show("删除操作已经完成,但是部门下面存在员工的将不会删除");

    }
    protected void BtnReflash_Click(object sender, EventArgs e)
    {
        BindGvList();
    }


    protected void Window1_Close(object sender, WindowCloseEventArgs e)
    {
        BindGvList();
    }

}